# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

class Solution:
    def rightSideView(self, root):
        if not root:
            return []
        else:
            right = self.rightSideView(root.right)
            left = self.rightSideView(root.left)
            return [root.val] + (right if len(right) > len(left) else right + left[len(right):])
